<template>
  <div class="top">
    <h1>数据可视化-ECharts</h1>
    <div class="showTime">{{ nowDate }}</div>
  </div>
</template>
<script>
export default {
  name: "Top",
  data() {
    return {
      nowDate: "",
    };
  },
  created() {
    this.getCurrentTime();
  },
  methods: {
    getCurrentTime() {
      //添加定时器
      setInterval(() => {
        //转换当前时间，这里也可以单独封装成一个函数
        let y = new Date().getFullYear();
        let m = new Date().getMonth() + 1;
        let d = new Date().getDate();
        let h = new Date().getHours();
        let mm =
          new Date().getMinutes() < 10
            ? "0" + new Date().getMinutes()
            : new Date().getMinutes();
        let s =
          new Date().getSeconds() < 10
            ? "0" + new Date().getSeconds()
            : new Date().getSeconds();
        this.nowDate =
          y + "年" + m + "月" + d + "日" + "  " + h + ":" + mm + ":" + s;
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/utils.scss";
.top {
  position: relative;
  height: 6vh;
  background: url("../assets/images/head_bg.png") no-repeat;
  background-size: 100% 100%;
  .showTime {
    position: absolute;
    right: vw(30);
    top: 0;
    line-height: vh(75);
    color: rgba(255, 255, 255, 0.7);
    font-size: vh(20);
  }
}
h1 {
  font-size: vw(30);
  color: #fff;
  text-align: center;
  line-height: vh(75);
}
</style>
